package lesson3.slides.xml.jaxb;

import java.io.File;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import lesson3.slides.xml.jaxb.generated.GreetingListType;
import lesson3.slides.xml.jaxb.generated.GreetingType;
import lesson3.slides.xml.jaxb.generated.ObjectFactory;

public class UsingGeneratedInput {

    public static void main(String[] args) throws JAXBException {
       ObjectFactory of = new ObjectFactory();
        JAXBContext jc = JAXBContext.newInstance("lesson3.slides.xml.jaxb.generated");
        Unmarshaller um = jc.createUnmarshaller();
        File f = new File("thursday.xml");
        JAXBElement jaxbe = (JAXBElement) (um.unmarshal(f));
        GreetingListType greetings =
                (GreetingListType) jaxbe.getValue();
        List<GreetingType> greetingList = greetings.getGreeting();
        for (GreetingType g : greetingList) {
            System.out.println("lang is:" + g.getLanguage()
                    + "\n greeting is:" + g.getText());
        }

    }
}